import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () =>
      import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    meta: { title: '找不到网页' },
    component: () =>
      import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/pages/fast-search/index',
    children: [
      {
        path: 'pages',
        name: 'home',
        meta: { title: '首页' },
        component: () =>
          import('@/views/search/index'),
        children: [
          {
            path: 'fast-search',
            component: () =>
              import('@/views/fast-search/index/index.vue'),
            redirect: '/index',
            meta: {
              title: '快速检索'
            },
            children: [
              {
                path: 'index',
                meta: {
                  title: '检索'
                },
                component: () =>
                  import('@/views/fast-search/home/index.vue')
              },
              {
                path: 'list',
                meta: {
                  title: '概览'
                },
                component: () =>
                  import('@/views/fast-search/list/index.vue')
              },
              {
                path: 'info',
                meta: {
                  title: '详览'
                },
                component: () =>
                  import('@/views/fast-search/info/index.vue')
              },
              {
                path: 'carousel',
                meta: {
                  title: '详览'
                },
                component: () =>
                  import('@/views/fast-search/info/caroused.vue')
              },
              {
                path: 'advanced-search',
                component: () =>
                  import('@/views/fast-search/advanced-search/index'),
                meta: {
                  title: '高级检索'
                }
              },
              {
                path: 'evidence-confirm-search',
                component: () =>
                  import('@/views/fast-search/evidence-confirm-search/index'),
                meta: {
                  title: '证据认定检索'
                }
              },
              {
                path: 'legal-question-search',
                component: () =>
                  import('@/views/fast-search/legal-question-search/index'),
                meta: {
                  title: '法律问题检索'
                }
              },
              {
                path: 'legislation-question-search',
                component: () =>
                  import('@/views/fast-search/legislation-question-search/index'),
                meta: {
                  title: '法律问题检索'
                }
              }
            ]
          },
          {
            path: 'research',
            meta: { title: '研究' },
            component: () =>
              import('@/views/research/index.vue'),
            children: [
              {
                path: 'sample-list',
                meta: { title: '样本列表' },
                component: () =>
                  import('@/views/research/sample-list/index.vue')
              },
              {
                path: 'sample-addition',
                meta: { title: '样本添加标引' },
                component: () =>
                  import('@/views/research/sample-addition/index.vue')
              },
              {
                path: 'sample-manage',
                meta: { title: '样本管理' },
                component: () =>
                  import('@/views/research/sample-manage/index.vue')
              }
            ]
          },
          {
            path: 'manage',
            meta: { title: '管理' },
            component: () =>
              import('@/views/manage/index.vue'),
            children: [
              {
                path: 'personal-manage',
                meta: { title: '个人管理' },
                component: () =>
                  import('@/views/manage/personal-manage/index.vue')
              },
              {
                path: 'statistics-manage',
                meta: { title: '处室案例统计' },
                component: () =>
                  import('@/views/manage/statistics-manage/index.vue')
              }
            ]
          },
          {
            path: 'overview',
            component: () =>
              import('@/views/overview/index'),
            meta: {
              title: '概览'
            }
          },
          {
            path: 'details',
            component: () =>
              import('@/views/details/index'),
            meta: {
              title: '详览'
            }
          },
          {
            path: 'search-history',
            component: () =>
              import('@/views/search-history/index'),
            meta: {
              title: '检索历史'
            }
          },
          {
            path: 'derive-low-case',
            component: () =>
              import('@/views/derive-low-case/index'),
            meta: {
              title: '以案说法'
            }
          },
          {
            path: 'upload-center',
            component: () =>
              import('@/views/upload-center/index'),
            meta: {
              title: '下载中心'
            }
          }
        ]
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
